package cn.sciento.boot.transfer.autoconfigure;

import cn.sciento.boot.data.change.handler.DataChangeBaseHandler;
import cn.sciento.boot.transfer.handler.DataTansferHandler;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@ComponentScan({"cn.sciento.boot.transfer"})
@EnableFeignClients({"cn.sciento.boot.transfer"})
@EnableConfigurationProperties({TransferProperty.class})
@EnableAsync
public class TransferConfiguration {
  @Bean
  @ConditionalOnProperty(prefix = "stong.transfer", name = {"enable"}, havingValue = "true")
  public DataChangeBaseHandler dataTansferHandler() {
    return (DataChangeBaseHandler)new DataTansferHandler();
  }
  
  @Bean
  @Qualifier("stong-boot-transfer-executor")
  public AsyncTaskExecutor ldapAsyncTaskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("stong-boot-transfer-executor");
    executor.setMaxPoolSize(3);
    executor.setCorePoolSize(2);
    return (AsyncTaskExecutor)executor;
  }
}
